
layui.define(['table', 'form'], function(exports){
  var $ = layui.$
  ,table = layui.table
  ,form = layui.form;

  //文章管理
  table.render({
    elem: '#LAY-app-content-list'
    ,url: layui.setter.prefixUrl + 'GetGameList' //模拟接口
    ,cols: [[
      {type: 'checkbox', fixed: 'left'}
      ,{field: 'name', align: 'center',width: 200, title: '名称', sort: true}
	    ,{field: 'runState', align: 'center',width: 150, title: '运行状态',  templet: function (d) {
	   
		   if(d.type == 0)
		   {
				return "<p p style='color: #009688;'>运行中</p>"
		   }
		   else
		   {
				return "<p p style='color: #FF5722;'>停止</p>"
		   }
	  
	   
	   },sort: true}
		
	  ,{field: 'playerTime', align: 'center',width: 200, title: '游戏时长（分钟）', sort: true}
	  
	   ,{field: 'checkCode', align: 'center',width: 200, title: '入队密码', sort: true}
	  
		
      ,{field: 'createTime', align: 'center',Width: 200,title: '创建时间',
	  templet: function (d) {
	   
	  // date.setTime(d.createTime);
	   
	   return formatServerDateTime(d.createTime);
	   
	   },
	  
	  sort: true}
      ,{title: '操作', minWidth: 150, align: 'center', fixed: 'right', toolbar: '#table-content-list'}
    ]]
    ,page: true
    ,limit: 10
    ,limits: [10, 15, 20, 25, 30]
    ,text: '对不起，加载出现异常！'
  });
  
  //监听工具条
  table.on('tool(LAY-app-content-list)', function(obj){
    var data = obj.data;
    if(obj.event === 'del'){
      layer.confirm('确定删除此条数据吗', function(index){
		var url = layui.setter.prefixUrl + "Professional/Delete/"+data.ID;
		$.post(url, function(data){ 
				 if(data.code==0)
				 {
					 table.reload('LAY-app-content-list');
					  layer.close(index); 
				 }
		 });
       
      });
    } else if(obj.event === 'edit'){
      layer.open({
        type: 2
        ,title: '编辑专业'
        ,content: '../../../views/dataManager/professional/listform.html?ID='+ data.ID
        ,maxmin: true
        ,area: ['550px', '350px']
        ,btn: ['确定', '取消']
        ,yes: function(index, layero){
			
          var iframeWindow = window['layui-layer-iframe'+ index]
          ,submit = layero.find('iframe').contents().find("#layuiadmin-app-form-edit");

          //监听提交
          iframeWindow.layui.form.on('submit(layuiadmin-app-form-edit)', function(data){
            var field = data.field; //获取提交的字段
			var url = layui.setter.prefixUrl + "Professional/Edit/";
			$.post(url, field,function(data){ 
						
						 if(data.code==0)
						 {
							 table.reload('LAY-app-content-list');
							 layer.close(index);
							 layer.alert("修改成功");
						 }
						 else
						 {
							 layer.alert(data.msg);
						 }
					
				 });
            
          });  
          
          submit.trigger('click');
        }
      });
    }
  });
  
  exports('game', {})
});